package org.example.src.repository;

import org.example.src.entity.JobPost;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public interface JobPostRepository extends JpaRepository<JobPost, Long> {
    @Query("SELECT j FROM JobPost j WHERE j.company.id = :companyId")
    List<JobPost> findByCompanyId(@Param("companyId") Long companyId);

    @Query("SELECT j FROM JobPost j WHERE j.isActive = :isActive")
    List<JobPost> findByActiveStatus(@Param("isActive") Boolean isActive);

    @Query("SELECT j FROM JobPost j WHERE j.title LIKE %:keyword% OR j.description LIKE %:keyword%")
    List<JobPost> searchByKeyword(@Param("keyword") String keyword);

    @Query("SELECT j FROM JobPost j WHERE j.location = :location")
    List<JobPost> findByLocation(@Param("location") String location);

    @Query("SELECT j FROM JobPost j WHERE j.endDate >= :currentDate")
    List<JobPost> findActiveJobs(@Param("currentDate") LocalDate currentDate);

    @Query("SELECT j FROM JobPost j WHERE j.company.isApproved = true AND j.isActive = true")
    List<JobPost> findActiveJobsFromApprovedCompanies();

    @Query("SELECT COUNT(j) FROM JobPost j WHERE j.company.id = :companyId")
    Long countByCompanyId(@Param("companyId") Long companyId);
}